/** @format */

import React from "react";
import { Navigate, RouteObject } from "react-router-dom";

const Home = React.lazy(() => import("../page/home"));
const Head = React.lazy(() => import("../page/head"));
const Square = React.lazy(() => import("../page/square"));
const LearningPath = React.lazy(() => import("../page/learningPath"));
const Login = React.lazy(() => import("../page/login")); // 登录页面
const Register = React.lazy(() => import("../page/register")); // 注册页面
const NotFound = React.lazy(() => import("../page/notFound")); // 404 页面

const RouterPath = {
  home: "/home",
  head: "/home/head",
  square: "/home/square",
  learningPath: "/home/learningPath",
  login: "/login",
  register: "/register",
  notFound: "*", // 404 页面路径
};

// 路由守卫
const PrivateRoute = ({ element }: { element: React.ReactNode }) => {
  const isLoggedIn = true; // 根据实际登录状态判断
  return isLoggedIn ? element : <Navigate to={RouterPath.login} />;
};

const router: RouteObject[] = [
  { index: true, element: <Navigate to={RouterPath.home} /> },
  // 首页路由
  {
    path: RouterPath.home,
    element: <Home />,
    children: [
      { index: true, element: <Navigate to={RouterPath.head} /> },
      { path: RouterPath.head, element: <Head /> },
      { path: RouterPath.square, element: <Square /> },
      { path: RouterPath.learningPath, element: <LearningPath /> },
    ],
  },
  // // 登录页路由
  {
    path: RouterPath.login,
    element: <Login />,
  },
  // 注册页路由
  {
    path: RouterPath.register,
    element: <Register />,
  },
  // 404 页面路由
  {
    path: RouterPath.notFound,
    element: <NotFound />,
  },
];

export { router, RouterPath };
